﻿package mortal.game.view.copy.defenseCopy.view
{
    import com.mui.display.*;
    import flash.events.*;
    import flash.utils.*;
    import mortal.common.*;
    import mortal.common.swfPlayer.*;
    import mortal.common.swfPlayer.data.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;
    import mx.utils.*;

    public class DefenseEquipItem extends BaseItem
    {
        public var equipType:int;
        private var _effectPlayer:SWFPlayer;
        private var _selectFilter:ScaleBitmap;
        private var _intervalId:int = 0;

        public function DefenseEquipItem(param1:int)
        {
            this.equipType = param1;
            return;
        }// end function

        override public function set itemData(param1:ItemData) : void
        {
            super.itemData = param1;
            if (param1)
            {
                if (_cdData == null || _cdData && !_cdData.isCoolDown)
                {
                    updateCDEffect(SkillUtil.getSkillSeries(this.skillId), CDDataType.skillSeries);
                }
            }
            else
            {
                updateCDEffect();
            }
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.buttonMode = true;
            this.isShowLeftTimeEffect = true;
            this.isShowFreezingEffect = true;
            this._selectFilter = ResourceConst.getScaleBitmap(ImagesConst.selectFilter, -3, -3, 46, 46);
            bgName = ImagesConst.DefenseCopyItemBg;
            this.configEventListener(MouseEvent.CLICK, this.onClickHandler);
            this.configEventListener(MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.configEventListener(MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }// end function

        private function onMouseOver(event:MouseEvent) : void
        {
            this.addChildAt(this._selectFilter, 0);
            return;
        }// end function

        private function onMouseOut(event:MouseEvent) : void
        {
            DisplayUtil.removeMe(this._selectFilter);
            return;
        }// end function

        private function onClickHandler(event:MouseEvent) : void
        {
            var _loc_3:Object = null;
            if (this.itemData == null)
            {
                return;
            }
            if (StringUtil.isWhitespace(itemData.itemInfo.skill))
            {
                return;
            }
            if (Cache.instance.role.roleEntityInfo.isDead)
            {
                return;
            }
            var _loc_2:* = this.skillId;
            if (_loc_2 > 0)
            {
                _loc_3 = {};
                _loc_3.entityIds = [];
                _loc_3.skillId = _loc_2;
                Dispatcher.dispatchEvent(new DataEvent(EventName.DefenseCopyUseEquip, _loc_3));
            }
            return;
        }// end function

        private function get skillId() : int
        {
            var _loc_1:int = 0;
            var _loc_2:Array = null;
            if (itemData && itemData.itemInfo.skill && itemData.itemInfo.skill.indexOf("#"))
            {
                _loc_2 = itemData.itemInfo.skill.split("#");
                _loc_1 = SkillUtil.isBeidongSkill(_loc_2[0]) ? (_loc_2[1]) : (_loc_2[0]);
            }
            else if (itemData)
            {
                _loc_1 = int(itemData.itemInfo.skill);
            }
            return _loc_1;
        }// end function

        private function effectLoaded(param1:SWFPlayer) : void
        {
            this._effectPlayer.move(-3, 20);
            this.addChild(this._effectPlayer);
            this._intervalId = setTimeout(this.removeEffect, 2000);
            return;
        }// end function

        private function removeEffect() : void
        {
            clearTimeout(this._intervalId);
            if (this._effectPlayer)
            {
                this._effectPlayer.stop();
                DisplayUtil.removeMe(this._effectPlayer);
            }
            return;
        }// end function

        public function addEffect() : void
        {
            if (this._effectPlayer == null)
            {
                this._effectPlayer = UIFactory.getUICompoment(SWFPlayer);
                this._effectPlayer.loadComplete = this.effectLoaded;
            }
            this._effectPlayer.load("ArroundEffect.swf", ModelType.NormalSwf, null);
            this._effectPlayer.play();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._intervalId = 0;
            this._selectFilter.dispose(param1);
            if (this._effectPlayer)
            {
                this._effectPlayer.dispose(param1);
            }
            this._effectPlayer = null;
            return;
        }// end function

    }
}
